cc.Class({
    extends: cc.Component,

    properties: {
        DirTipsNode: cc.Node,
        DirTipsTime: cc.Node,
        _dir: 1, // 1~4 东南西北
        dir: {
            get() { return this._dir; },
            set(n) {
                this._dir = n;
                if (this.DirTipsNode) {
                    this.DirTipsNode.rotation = (this._dir - 1) * 90;
                }
                if (this.DirTipsTime) {
                    this.DirTipsTime.rotation = -(this._dir - 1) * 90;
                }
            },
        },

        _curturn: 0,
        curTurn: {
            get() {
                return this._curturn;
            },
            set(n) {
                this._curturn = n;
                if (this._curturn == 0) {
                    this.clearTurns();
                } else {
                    this.clearTurns();
                    this.tips[this._curturn - 1].active = true;
                }
            }
        },
        tips: [cc.Node],

        _timer: 15,
        time: {
            set(n) {
                this._timer = n;
                if (n == 0) {
                    this.stopTimer();
                } else {
                    this.startTimer();
                }
            },
        },
        _isrunning: false,
    },

    // onLoad () {},

    start() {
        this.time = 0;
    },

    clearTurns() {
        for (const node of this.tips) {
            node.active = false;
        }
    },

    timerUpdate() {
        this._timer--;
        let timerstr = this._timer;
        if (this._timer <= 0) {
            this._timer = 0;
            this.stopTimer();
        }
        if (this._timer < 10) {
            timerstr = '0' + this._timer;
        }
        if (this._timer == 1) {
            cc.ll.AudioMgr.playAudio('TuiBing/lhd_game_timeout2');
        }
        else if (this._timer < 5) {
            cc.ll.AudioMgr.playAudio('TuiBing/lhd_game_timeout1');
        }
        let timerlabel = this.DirTipsTime.getComponent(cc.Label);
        timerlabel.string = timerstr;
    },

    stopTimer() {
        this._isrunning = false;
        this.unschedule(this.timerUpdate);
        let timerlabel = this.DirTipsTime.getComponent(cc.Label);
        timerlabel.string = '00';
    },

    startTimer(n) {
        if (n != null && typeof (n) == 'number') {
            this._timer = n;
        }
        if (!this._isrunning) {
            this.schedule(this.timerUpdate, 1);
        }
        this._isrunning = true;
    },
});
